package com.ikas.ai.server.module.system.model;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@TableName("t_cfg_menu_permissions")
public class Permission {
    /**
     * 菜单编码
     */
    @TableId(type = IdType.AUTO)
    private Long id;

    /**
     * 菜单编码
     */
    private String code;

    /**
     * 菜单名称
     */
    @NotEmpty(message = "菜单名称必填")
    private String name;

    /**
     * 权限
     */
    private String permissions;

    /**
     * 级别
     */
    @NotNull(message = "菜单级别必填")
    private Integer menuLevel;

    /**
     * 上级菜单编码
     */
    @NotNull(message = "上级菜单必填")
    private Long pid;

    /**
     * 父菜单名称
     */
    @TableField(exist = false)
    private String pName;

    /**
     * 图标
     */
    private String icon;

    /**
     * 顺序
     */
    private Integer orderby = 0;
    /**
     * 权限路径
     */
    private String url;
    /**
     * 菜单类型 0：目录   1：菜单   2：按钮
     */
    @NotNull(message = "菜单类型必填")
    private Integer type;

    /**
     * 是否隐藏 0：是   1：否
     */
    private Integer hidden = 1;

    /**
     * 重定向路径
     */
    private String redirect;

    /**
     * ztree属性
     */
    @TableField(exist = false)
    private Boolean open;

    @TableField(exist = false)
    private List<Permission> childrenList = new ArrayList<>();

    @Override
    public String toString() {
        return "Permission{" +
                "id=" + id +
                ", code='" + code + '\'' +
                ", name='" + name + '\'' +
                ", permissions='" + permissions + '\'' +
                ", menuLevel=" + menuLevel +
                ", pid=" + pid +
                ", pName='" + pName + '\'' +
                ", icon='" + icon + '\'' +
                ", orderby=" + orderby +
                ", url='" + url + '\'' +
                ", type=" + type +
                ", open=" + open +
                ", childrenList=" + childrenList +
                '}';
    }

    /**
     * 获取菜单编码
     *
     * @return id - 菜单编码
     */
    public Long getId() {
        return id;
    }

    /**
     * 设置菜单编码
     *
     * @param id 菜单编码
     */
    public void setId(Long id) {
        this.id = id;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    /**
     * 获取菜单名称
     *
     * @return name - 菜单名称
     */
    public String getName() {
        return name;
    }

    /**
     * 设置菜单名称
     *
     * @param name 菜单名称
     */
    public void setName(String name) {
        this.name = name == null ? null : name.trim();
    }

    /**
     * 获取权限
     *
     * @return permissions - 权限
     */
    public String getPermissions() {
        return permissions;
    }

    /**
     * 设置权限
     *
     * @param permissions 权限
     */
    public void setPermissions(String permissions) {
        this.permissions = permissions == null ? null : permissions.trim();
    }

    /**
     * 获取级别
     *
     * @return menu_level - 级别
     */
    public Integer getMenuLevel() {
        return menuLevel;
    }

    /**
     * 设置级别
     *
     * @param menuLevel 级别
     */
    public void setMenuLevel(Integer menuLevel) {
        this.menuLevel = menuLevel;
    }

    /**
     * 获取上级菜单编码
     *
     * @return pid - 上级菜单编码
     */
    public Long getPid() {
        return pid;
    }

    /**
     * 设置上级菜单编码
     *
     * @param pid 上级菜单编码
     */
    public void setPid(Long pid) {
        this.pid = pid;
    }

    /**
     * 获取图标
     *
     * @return icon - 图标
     */
    public String getIcon() {
        return icon;
    }

    /**
     * 设置图标
     *
     * @param icon 图标
     */
    public void setIcon(String icon) {
        this.icon = icon == null ? null : icon.trim();
    }

    /**
     * 获取顺序
     *
     * @return order - 顺序
     */
    public Integer getOrderby() {
        return orderby;
    }

    /**
     * 设置顺序
     *
     * @param orderby 顺序
     */
    public void setOrderby(Integer orderby) {
        this.orderby = orderby;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getpName() {
        return pName;
    }

    public void setpName(String pName) {
        this.pName = pName;
    }

    public Boolean getOpen() {
        return open;
    }

    public void setOpen(Boolean open) {
        this.open = open;
    }

    public List<Permission> getChildrenList() {
        return childrenList;
    }

    public void setChildrenList(List<Permission> childrenList) {
        this.childrenList = childrenList;
    }

    public Integer getHidden() {
        return hidden;
    }

    public void setHidden(Integer hidden) {
        this.hidden = hidden;
    }

    public String getRedirect() {
        return redirect;
    }

    public void setRedirect(String redirect) {
        this.redirect = redirect;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        Permission that = (Permission) o;

        return new EqualsBuilder().append(id, that.id).append(code, that.code).append(name, that.name).append(permissions, that.permissions).append(menuLevel, that.menuLevel).append(pid, that.pid).append(pName, that.pName).append(icon, that.icon).append(orderby, that.orderby).append(url, that.url).append(type, that.type).append(hidden, that.hidden).append(redirect, that.redirect).append(open, that.open).append(childrenList, that.childrenList).isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37).append(id).append(code).append(name).append(permissions).append(menuLevel).append(pid).append(pName).append(icon).append(orderby).append(url).append(type).append(hidden).append(redirect).append(open).append(childrenList).toHashCode();
    }
}